##Load libraries and funtions --------------------

{library(lme4)
  library(haven)
  library(tidyverse)
  library(sjPlot)
  library(sjstats)
  library(jtools)
  library(ggplot2)
  library(jmv)
  library(margins)
  library(sjmisc)
  library(stats)
  library(broom.mixed) 
  library(Hmisc)
  library(stargazer)
  library(cowplot)
  library(srvyr)
  library(ggeffects)
  library("marginaleffects")
  library(forcats)
  
  
  options(scipen=999)# non-scientific notation
  
  getwd()
  setwd("/Users/adamstefkovics/Documents/SCIENCE/ESS/gender_ESS_full")
  
  data <- as.data.frame(read_sav('ESS11.sav'))
  
  int_data <- as.data.frame(read_sav('ESS11I.sav'))
  
  cntry_data <- as.data.frame(openxlsx::read.xlsx('cntry_level.xlsx'))
  
  data$idno_new <- paste(data$cntry, data$idno, sep = "_")
  int_data$idno_new <- paste(int_data$cntry, int_data$idno, sep = "_")
  int_data$intnum_new <- paste(int_data$cntry, int_data$intnum, sep = "_")
  
  ##joining
  data <- data %>% 
    left_join(select(int_data, -cntry,-essround), by = "idno_new")
  
  data <- merge(data,cntry_data,by="cntry",all.x = TRUE)
  
  ###exclude certain interviewers
  int_num <- data %>% 
    group_by(intnum_new) %>% 
    summarise(int_num=n()) %>% 
    filter(int_num<10)
  
  
  data <- merge(data,int_num,by="intnum_new",all.x=T) %>% 
    filter(is.na(int_num))
  
  gender_num <- data %>% 
    group_by(intnum_new,gndr) %>% 
    summarise(gender_case=n(),.groups = "drop") %>% 
    complete(intnum_new, gndr, fill = list(gender_case = 0)) %>% 
    filter(gndr==1) %>% 
    select(intnum_new,gender_case)
  
  
  data <- merge(data,gender_num,by="intnum_new",all.x=T) %>% 
    filter(gender_case>0)
  
  data <- data %>% filter(!is.na(intgndr))
  
  ###transform
  
  data <- data %>% 
    mutate(gender_health=case_when(trmdcnt==1~1,
                                   trmdcnt>1~0,
                                   TRUE~NA_real_),
           gender_work=case_when(trwkcnt==1~1,
                                 trwkcnt>1~0,
                                 TRUE~NA_real_),
           
           gender_police=case_when(trplcnt==1~1,
                                   trplcnt>1~0,
                                   TRUE~NA_real_),
           gender=gndr,
           gender_int=intgndr,
           marital=case_when(rshpsts==1~1,
                             rshpsts==4~1,
                             TRUE~0),
           work=case_when(pdwrk==1~1,
                          TRUE~0),
           child = case_when(
             rshipa2 == 2 | rshipa3 == 2 | rshipa4 == 2 | rshipa5 == 2 | 
               rshipa6 == 2 | rshipa7 == 2 | rshipa8 == 2 | rshipa9 == 2 | 
               rshipa10 == 2 | rshipa11 == 2 | rshipa12 == 2 | chldhhe==1 ~ 1,
             TRUE ~ 0),
           christian=case_when(rlgdnm<5~1,
                               TRUE~0),
           unfair_med=case_when(trmedmw<3~1,
                                TRUE~0),
           unfair_med_inr=case_when(is.na(unfair_med)~0,
                                    TRUE~1),
           unfair_work=case_when(trwrkmw<3~1,
                                 TRUE~0),
           unfair_work_inr=case_when(is.na(unfair_work)~0,
                                     TRUE~1),
           unfair_police=case_when(trplcmw<3~1,
                                   TRUE~0),
           unfair_police_inr=case_when(is.na(unfair_police)~0,
                                       TRUE~1),
           domicil_3=as.factor(case_when(domicil<3~3,
                                         domicil==3~2,
                                         domicil>3~1,
                                         TRUE~NA_real_)),
           unfair=case_when(unfair_med==1 ~1,
                            unfair_work==1~1,
                            unfair_police==1~1,
                            TRUE~0),
           relig=rlgdgr,
           edu_cat=case_when(edulvlb<313~1,
                             edulvlb %in% 313:423~2,
                             edulvlb > 423~3,
                             TRUE~NA_real_),
           edulvlb_cont = case_when(
             edulvlb == 0    ~ 1,
             edulvlb == 113  ~ 2,
             edulvlb == 129  ~ 3,
             edulvlb == 212  ~ 4,
             edulvlb == 213  ~ 5,
             edulvlb == 221  ~ 6,
             edulvlb == 222  ~ 7,
             edulvlb == 223  ~ 8,
             edulvlb == 229  ~ 9,
             edulvlb == 311  ~ 10,
             edulvlb == 312  ~ 11,
             edulvlb == 313  ~ 12,
             edulvlb == 321  ~ 13,
             edulvlb == 322  ~ 14,
             edulvlb == 323  ~ 15,
             edulvlb == 412  ~ 16,
             edulvlb == 413  ~ 17,
             edulvlb == 421  ~ 18,
             edulvlb == 422  ~ 19,
             edulvlb == 423  ~ 20,
             edulvlb == 510  ~ 21,
             edulvlb == 520  ~ 22,
             edulvlb == 610  ~ 23,
             edulvlb == 620  ~ 24,
             edulvlb == 710  ~ 25,
             edulvlb == 720  ~ 26,
             edulvlb == 800  ~ 27,
             edulvlb == 5555 ~ NA_real_,  # Handle Other/Missing values as NA
             edulvlb == 7777 ~ NA_real_,
             edulvlb == 8888 ~ NA_real_,
             edulvlb == 9999 ~ NA_real_,
             TRUE ~ NA_real_),  # Default to NA for all unrecognized values
           relig_reverse = case_when(
             rlgatnd == 1 ~ 7,
             rlgatnd == 2 ~ 6,
             rlgatnd == 3 ~ 5,
             rlgatnd == 4 ~ 4,
             rlgatnd == 5 ~ 3,
             rlgatnd == 6 ~ 2,
             rlgatnd == 7 ~ 1,
             TRUE ~ NA_real_),
           hincfel_rev = case_when(
             hincfel == 1 ~ 4,  
             hincfel == 2 ~ 3,  
             hincfel == 3 ~ 2,  
             hincfel == 4 ~ 1,
             TRUE ~ NA_real_),
           prewhp_new=case_when(is.na(prewhp)~0,
                                TRUE~prewhp),
           eqwrkbg_inr=case_when(is.na(prewhp)~0,
                                 TRUE~1),
           eqpolbg_inr=case_when(is.na(eqpolbg)~0,
                                 TRUE~1),
           eqmgmbg_inr=case_when(is.na(eqmgmbg)~0,
                                 TRUE~1),
           eqpaybg_inr=case_when(is.na(eqpaybg)~0,
                                 TRUE~1),
           eqparlv_inr=case_when(is.na(eqparlv)~0,
                                 TRUE~1),
           eqparep_inr=case_when(is.na(eqparep)~0,
                                 TRUE~1),
           freinsw_inr=case_when(is.na(freinsw)~0,
                                 TRUE~1),
           fineqpy_inr=case_when(is.na(fineqpy)~0,
                                 TRUE~1),
           wsekpwr_inr=case_when(is.na(wsekpwr)~0,
                                 TRUE~1),
           weasoff_inr=case_when(is.na(weasoff)~0,
                                 TRUE~1),
           wexashr_inr=case_when(is.na(wexashr)~0,
                                 TRUE~1),
           eqparlv_rev = case_when(
             eqparlv == 1 ~ 5,  
             eqparlv == 2 ~ 4, 
             eqparlv == 3 ~ 3,  
             eqparlv == 4 ~ 2,  
             eqparlv == 5 ~ 1,  
             eqparlv %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           eqparep_rev = case_when(
             eqparep == 1 ~ 5,  
             eqparep == 2 ~ 4, 
             eqparep == 3 ~ 3,  
             eqparep == 4 ~ 2,  
             eqparep == 5 ~ 1,  
             eqparep %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           freinsw_rev = case_when(
             freinsw == 1 ~ 5,  
             freinsw == 2 ~ 4, 
             freinsw == 3 ~ 3,  
             freinsw == 4 ~ 2,  
             freinsw == 5 ~ 1,  
             freinsw %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           fineqpy_rev = case_when(
             fineqpy == 1 ~ 5,  
             fineqpy == 2 ~ 4, 
             fineqpy == 3 ~ 3,  
             fineqpy == 4 ~ 2,  
             fineqpy == 5 ~ 1,  
             fineqpy %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           wsekpwr_rev = case_when(
             wsekpwr == 1 ~ 5,  
             wsekpwr == 2 ~ 4, 
             wsekpwr == 3 ~ 3,  
             wsekpwr == 4 ~ 2,  
             wsekpwr == 5 ~ 1,  
             wsekpwr %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           weasoff_rev = case_when(
             weasoff == 1 ~ 5,  
             weasoff == 2 ~ 4, 
             weasoff == 3 ~ 3,  
             weasoff == 4 ~ 2,  
             weasoff == 5 ~ 1,  
             weasoff %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           wexashr_rev = case_when(
             wexashr == 1 ~ 5,  
             wexashr == 2 ~ 4, 
             wexashr == 3 ~ 3,  
             wexashr == 4 ~ 2,  
             wexashr == 5 ~ 1,  
             wexashr %in% c(7, 8, 9) ~ NA_real_,  
             TRUE ~ NA_real_),
           vdcond_home=case_when(vdcond==1~1,
                                 TRUE~0),
           vdcond_out=case_when(vdcond==2~1,
                                TRUE~0),
           vdcond_video=case_when(vdcond==3~1,
                                  TRUE~0))
  
  #function to scale
  scale01 <- function(x){(x-min(x, na.rm = T))/(max(x, na.rm = T)-min(x, na.rm = T))} 
  
  frq(data,vdcond_video)
  data %>% filter(cntry=="SE") %>% 
    summarise(n_distinct(psu),n())
  
  data$gender <- as.factor(data$gender)
  data$gender_int <- as.factor(data$gender_int)
  data$vdcond <- as.factor(data$vdcond)
  data$prewhp_new <- as.factor(data$prewhp_new)
  data$lrscale_sc = scale01(data$lrscale)
  data$lrscale_c = scale(data$lrscale,center=TRUE,scale=FALSE)
  data$age_sc = scale01(data$agea)
  data$age_c = scale(data$agea,center=TRUE,scale=FALSE)
  data$intage_sc = scale01(data$intagea)
  data$intage_c = scale(data$intagea,center=TRUE,scale=FALSE)
  data$relig_reverse_sc = scale01(data$relig_reverse)
  data$relig_reverse_c = scale(data$relig_reverse_sc,center=TRUE,scale=FALSE)
  data$edulvlb_cont_sc = scale01(data$edulvlb_cont)
  data$edulvlb_cont_c = scale(data$edulvlb_cont,center=TRUE,scale=FALSE)
  data$gggi_sc = scale01(data$gggi)
  data$gii_sc = scale01(data$gii)
  data$mortality_sc = scale01(data$mortality)
  data$birth_sc = scale01(data$birth)
  data$seats_sc = scale01(data$seats)
  data$labor_sc = scale01(data$labor)
  data$vdcond_home <- as.factor(data$gender_int)
  data$vdcond_out <- as.factor(data$vdcond_out)
  data$vdcond_video <- as.factor(data$vdcond_video)
  data$vdcond <- as.factor(data$vdcond)
  data$unfair_med<-as.factor(data$unfair_med) 
  data$unfair_work<-as.factor(data$unfair_work) 
  data$unfair_police<-as.factor(data$unfair_police) 
  data$unfair<-as.factor(data$unfair) 
  
  
  ##creating gender dyads
  data <- data %>% 
    mutate(dyad=case_when(gender==1 & gender_int==1~1,
                          gender==1 & gender_int==2~2,
                          gender==2 & gender_int==1~3,
                          gender==2 & gender_int==2~4))
  
  data$dyad <- as.factor(data$dyad)
  
  
  ##exclude where PSU is not uniqe
  
  country_duplicate_flag <- data %>%
    group_by(cntry) %>%
    summarise(has_duplicates = ifelse(n() > n_distinct(psu), 1, 0)) 
  
  # Merge the flag back to the original dataset
  data <- data %>%
    left_join(country_duplicate_flag, by = "cntry") %>% 
    filter(has_duplicates == 1)
  
  

}


####DESC#gender_num###DESC

intnum_values <- unique(data$intnum_new)

# Filter 'int_data' where values in 'intnum_new' match 'int_data'
int_data <- int_data[int_data$intnum_new %in% intnum_values, ]

int_data <- int_data %>% select(intnum_new,cntry,intgndr) %>% group_by(intnum_new) %>% 
  summarise(intgndr=max(intgndr),
            cntry=first(cntry)) %>% 
  filter(!is.na(intgndr))

summary(int_data,cntry)

cntry_n_labels <- c(
  "AT" = "AT (N=2318)",
  "BE" = "BE (N=1510)",
  "DE" = "DE (N=2170)",
  "ES" = "ES (N=1793)",
  "FR" = "FR (N=1426)",
  "GB" = "GB (N=1008)",
  "GR" = "GR (N=2663)",
  "HR" = "HR (N=1272)",
  "HU" = "HU (N=1976)",
  "IE" = "IE (N=1955)",
  "IS" = "IS (N=800)",
  "IT" = "IT (N=2415)",
  "LT" = "LT (N=1223)",
  "PL" = "PL (N=1173)",
  "PT" = "PT (N=1300)",
  "RS" = "RS (N=1138)",
  "SI" = "SI (N=1187)",
  "SK" = "SK (N=1240)"
)

p <- int_data %>%
  group_by(cntry, intgndr) %>%
  summarize(n = n(), .groups = "drop") %>%
  group_by(cntry) %>%
  mutate(prop = n / sum(n) * 100) %>%
  ungroup() %>%
  pivot_wider(names_from = intgndr, values_from = c(n, prop)) %>%
  mutate(
    diff = prop_1 - prop_2,
    label = cntry_n_labels[cntry],
    label = fct_reorder(label, diff, .desc = FALSE)
  ) %>%
  pivot_longer(cols = c(prop_1, prop_2), names_to = "var", values_to = "prop") %>%
  mutate(var = recode(var, "prop_1" = "Male", "prop_2" = "Female")) %>%
  ggplot(aes(x = label, y = prop, fill = var)) +
  geom_bar(stat = "identity", position = "stack") +
  geom_hline(yintercept = 50, color = "grey75", linetype = "dashed") +
  scale_fill_manual(
    values = c("Male" = "#3e5483", "Female" = "#688cdb"),
    labels = c("Male interviewer", "Female interviewer")
  ) +
  labs(x = "", y = "%", fill = "") +
  coord_flip() +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 10),
    panel.grid = element_line()
  )

p
ggsave("desc_cntry.png",p,h=6,w=6,dpi=300)

###INR

med <- data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(intgndr,unfair_med) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair_med,
         var=as.factor(var)) %>% 
  select(var, prop) %>% 
  filter(var==1) %>% 
  pivot_wider(names_from = intgndr, values_from = prop,
              names_glue = "prop_{intgndr}") %>% 
  mutate(label=c("Medical treatment")) %>% 
  rename(Male_interviewer=prop_1) %>% 
  rename(Female_interviewer=prop_2) %>% 
  select(label,Male_interviewer,Female_interviewer)
med
work <- data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(intgndr,unfair_work) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair_work,
         var=as.factor(var)) %>% 
  select(var, prop) %>% 
  filter(var==1) %>% 
  pivot_wider(names_from = intgndr, values_from = prop,
              names_glue = "prop_{intgndr}") %>% 
  mutate(label=c("Work")) %>% 
  rename(Male_interviewer=prop_1) %>% 
  rename(Female_interviewer=prop_2) %>% 
  select(label,Male_interviewer,Female_interviewer)

police <-data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(intgndr,unfair_police) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair_police,
         var=as.factor(var)) %>% 
  select(var, prop) %>% 
  filter(var==1) %>% 
  pivot_wider(names_from = intgndr, values_from = prop,
              names_glue = "prop_{intgndr}") %>% 
  mutate(label=c("Police encounter")) %>% 
  rename(Male_interviewer=prop_1) %>% 
  rename(Female_interviewer=prop_2) %>% 
  select(label,Male_interviewer,Female_interviewer)

any <-data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(intgndr,unfair) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair,
         var=as.factor(var)) %>% 
  select(var, prop) %>% 
  filter(var==1) %>% 
  pivot_wider(names_from = intgndr, values_from = prop,
              names_glue = "prop_{intgndr}") %>% 
  mutate(label=c("Any domain")) %>% 
  rename(Male_interviewer=prop_1) %>% 
  rename(Female_interviewer=prop_2) %>% 
  select(label,Male_interviewer,Female_interviewer)

p<- med %>% 
  full_join(work) %>% 
  full_join(police) %>% 
  full_join(any) %>% 
  mutate(across(where(is.numeric), round, digits = 2))  # Rounds all numeric columns to 2 decimal places
p
stargazer::stargazer(p,summary=F,rownames = F)

###sig

design <- data_w %>%
  as_survey(weights = pspwght)

# Chi-squared test between interviewer gender (intgndr) and unfairness (unfair_med)

svychisq(~ intgndr + unfair, design)

sjstats::chi_squared_test(data, "unfair_med", by="gender_int", weights = "pspwght")
sjstats::chi_squared_test(data, "unfair_work", by="gender_int", weights = "pspwght")
sjstats::chi_squared_test(data, "unfair_police", by="gender_int", weights = "pspwght")
sjstats::chi_squared_test(data, "unfair", by="gender_int", weights = "pspwght")


###dyad

med <- data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(dyad,unfair_med) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair_med,
         var=as.factor(var)) %>% 
  select(var, prop) %>% 
  filter(var==1) %>% 
  pivot_wider(names_from = dyad, values_from = prop,
              names_glue = "prop_{dyad}") %>% 
  mutate(label=c("Medical treatment")) %>% 
  rename(Male_male=prop_1) %>% 
  rename(Male_female=prop_2) %>% 
  rename(Female_male=prop_3) %>% 
  rename(Female_female=prop_4) %>% 
  select(label,Male_male,Male_female,Female_male,Female_female)

med
work <- data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(dyad,unfair_work) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair_work,
         var=as.factor(var)) %>% 
  select(var, prop) %>% 
  filter(var==1) %>% 
  pivot_wider(names_from = dyad, values_from = prop,
              names_glue = "prop_{dyad}") %>% 
  mutate(label=c("Work")) %>% 
  rename(Male_male=prop_1) %>% 
  rename(Male_female=prop_2) %>% 
  rename(Female_male=prop_3) %>% 
  rename(Female_female=prop_4) %>% 
  select(label,Male_male,Male_female,Female_male,Female_female)

police <-data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(dyad,unfair_police) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair_police,
         var=as.factor(var)) %>% 
  select(var, prop) %>%   filter(var==1) %>% 
  pivot_wider(names_from = dyad, values_from = prop,
              names_glue = "prop_{dyad}") %>% 
  mutate(label=c("Police encounter")) %>% 
  rename(Male_male=prop_1) %>%
  rename(Male_female=prop_2) %>% 
  rename(Female_male=prop_3) %>% 
  rename(Female_female=prop_4) %>% 
  select(label,Male_male,Male_female,Female_male,Female_female)


any <-data_w %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(dyad,unfair) %>% 
  summarise(prop = survey_mean()*100) %>% 
  mutate(var=unfair,
         var=as.factor(var)) %>% 
  select(var, prop) %>% filter(var==1) %>% 
  pivot_wider(names_from = dyad, values_from = prop,
              names_glue = "prop_{dyad}") %>% 
  mutate(label=c("Any domain")) %>% 
  rename(Male_male=prop_1) %>%
  rename(Male_female=prop_2) %>% 
  rename(Female_male=prop_3) %>% 
  rename(Female_female=prop_4) %>% 
  select(label,Male_male,Male_female,Female_male,Female_female)

p<- med %>% 
  full_join(work) %>% 
  full_join(police) %>% 
  full_join(any)  %>% 
  mutate(across(where(is.numeric), round, digits = 2))  # Rounds all numeric columns to 2 decimal places

p
stargazer::stargazer(p,summary=F,rownames = F)


###sig

design_male <- data_w %>%
  filter(dyad<3) %>%
  as_survey(weights = pspwght)

design_female <- data_w %>%
  filter(dyad>2) %>%
  as_survey(weights = pspwght)

# Chi-squared test between interviewer gender (intgndr) and unfairness (unfair_med)

svychisq(~ intgndr + unfair_med, design_male)
svychisq(~ intgndr + unfair_work, design_male)
svychisq(~ intgndr + unfair_police, design_male)
svychisq(~ intgndr + unfair, design_male)

svychisq(~ intgndr + unfair_med, design_female)
svychisq(~ intgndr + unfair_work, design_female)
svychisq(~ intgndr + unfair_police, design_female)
svychisq(~ intgndr + unfair, design_female)

data %>% 
  filter(dyad<3) %>% chi_squared_test("unfair_med", by="dyad", weights = "pspwght")

data %>% 
  filter(dyad>2) %>% chi_squared_test("unfair_med", by="dyad", weights = "pspwght")

data %>% 
  filter(dyad<3) %>% chi_squared_test("unfair_work", by="dyad", weights = "pspwght")

data %>% 
  filter(dyad>2) %>% chi_squared_test("unfair_work", by="dyad", weights = "pspwght")


data %>% 
  filter(dyad<3) %>% chi_squared_test("unfair_police", by="dyad", weights = "pspwght")

data %>% 
  filter(dyad>2) %>% chi_squared_test("unfair_police", by="dyad", weights = "pspwght")

data %>% 
  filter(dyad<3) %>% chi_squared_test("unfair", by="dyad", weights = "pspwght")

data %>% 
  filter(dyad>2) %>% chi_squared_test("unfair", by="dyad", weights = "pspwght")

###H2

t.test(eqwrkbg ~ gender_int, data = data, var.equal = TRUE) 
frq(data,eqwrkbg)


###plotting descriptives

#EQ1

{a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqwrkbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqwrkbg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqwrkbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqwrkbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(), 
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Gender equality in family life", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqwrkbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqwrkbg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqwrkbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqwrkbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqwrkbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqwrkbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqwrkbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqwrkbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figeq1.png",p1,h=10,w=10,dpi=100)

###EQ2

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpolbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpolbg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpolbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpolbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Gender equality in politics", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpolbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpolbg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpolbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpolbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpolbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpolbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpolbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpolbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figeq2.png",p1,h=10,w=10,dpi=100)

###EQ3

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqmgmbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqmgmbg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqmgmbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqmgmbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Gender equality in work", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqmgmbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqmgmbg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqmgmbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqmgmbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqmgmbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqmgmbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqmgmbg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqmgmbg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figeq3.png",p1,h=10,w=10,dpi=100)

##EQ4

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpaybg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpaybg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpaybg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpaybg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Gender equality in economy", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpaybg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpaybg),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpaybg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpaybg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpaybg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpaybg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqpaybg) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqpaybg),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Very bad","1","2",
                                   "3","4","5","Very good"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figeq4.png",p1,h=10,w=10,dpi=100)


##POLICY parl

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparep) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparep),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparep) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparep),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Policy - parliament", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparep) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparep),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparep) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparep),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparep) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparep),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparep) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparep),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figp1.png",p1,h=10,w=10,dpi=100)


##POLICY parent

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparlv) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparlv),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparlv) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparlv),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Policy - parental leave", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparlv) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparlv),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
c
d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparlv) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparlv),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparlv) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparlv),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(eqparlv) %>% 
  summarise(prop = survey_mean()) %>% 
    mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(eqparlv),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figp2.png",p1,h=10,w=10,dpi=100)


##POLICY insult

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(freinsw) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(freinsw),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(freinsw) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(freinsw),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Policy - insult", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(freinsw) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(freinsw),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
c
d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(freinsw) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(freinsw),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(freinsw) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(freinsw),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(freinsw) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(freinsw),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figp3.png",p1,h=10,w=10,dpi=100)


##POLICY payment

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(fineqpy) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(fineqpy),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(fineqpy) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(fineqpy),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Policy - payment", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(fineqpy) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(fineqpy),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
c
d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(fineqpy) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(fineqpy),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(fineqpy) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(fineqpy),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(fineqpy) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(fineqpy),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.55),
                     name="")+
  scale_x_discrete(name="",label=c("Strongly in favour", "2",
                                   "3",
                                   "4",
                                   "Strongly against"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figp4.png",p1,h=10,w=10,dpi=100)


##STEREO control


a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wsekpwr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wsekpwr),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wsekpwr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wsekpwr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Stereotype - control", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wsekpwr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wsekpwr),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
c
d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wsekpwr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wsekpwr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wsekpwr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wsekpwr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wsekpwr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wsekpwr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figst1.png",p1,h=10,w=10,dpi=100)

#STEREO offend

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(weasoff) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(weasoff),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(weasoff) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(weasoff),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Stereotype - offend", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(weasoff) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(weasoff),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
c
d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(weasoff) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(weasoff),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(weasoff) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(weasoff),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(weasoff) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(weasoff),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figst2.png",p1,h=10,w=10,dpi=100)


#STEREO exa

a<- data %>% 
  filter(gender_int==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wexashr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wexashr),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male interviewer (N=9896)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
a
b<- data %>% 
  filter(gender_int==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wexashr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wexashr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female interviewer (N=18671)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

grida <- plot_grid(a,b,nrow=1,labels=c("a",""))
title <- ggdraw() + draw_label("Stereotype - exaggerate", fontface = 'bold')

c<- data %>% 
  filter(dyad==1) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wexashr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wexashr),prop))+
  geom_bar(stat="identity",fill="#688cdb", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male resp. - male int. (N=4807)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
c
d<- data %>% 
  filter(dyad==2) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wexashr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wexashr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Male resp. - female int. (N=8352)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())

e<- data %>% 
  filter(dyad==3) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wexashr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wexashr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female resp. - male int. (N=5089)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

f<- data %>% 
  filter(dyad==4) %>% 
  as_survey(weights = c(pspwght)) %>%
  group_by(wexashr) %>% 
  summarise(prop = survey_mean()) %>% 
  mutate(label=scales::percent(prop,accuracy=0.1)) %>% 
  ggplot(aes(factor(wexashr),prop))+
  geom_bar(stat="identity",fill="#3e5483", 
           position=position_dodge())+
  geom_text(aes(label=label),position = position_dodge(width = 1),
            vjust=-0.5)+
  scale_y_continuous(labels=scales::percent,limits=c(0,0.65),
                     name="")+
  scale_x_discrete(name="",label=c("Never", "Rarely",
                                   "Sometimes",
                                   "Often",
                                   "Alwyas"))+
  ggtitle("Female resp. - female int. (N=10319)")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x=element_blank())
b

gridb <- plot_grid(c,d,e,f,nrow=2,labels=c("b","","",""))

p1 <- plot_grid(title, grida, gridb,ncol = 1, rel_heights = c(0.1, 0.3,0.6))
p1

ggsave("figst3.png",p1,h=10,w=10,dpi=100)
}
